package com.kang.controller;

import com.kang.service.LikeService;
import com.kang.util.WebResponse;
import com.kang.vo.ParamInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@Api(tags = "点赞接口")
@RequestMapping("/user/like")
@Slf4j
public class LikeController {

    @Autowired
    private LikeService likeService;


    @ApiOperation("点赞")
    @PostMapping("insertLike")
    public WebResponse insertLike(HttpServletRequest request, @RequestBody ParamInfo ParamInfo) {
        try {
            return WebResponse.resSuccess("点赞成功",likeService.insertLike(request,ParamInfo.getEssayId()));
        } catch (Exception ex) {
            log.error("点赞失败",ex);
            return WebResponse.resFail("点赞失败",null);
        }
    }

    @ApiOperation("取消点赞")
    @PostMapping("updateLike")
    public WebResponse updateLike(HttpServletRequest request, @RequestBody ParamInfo ParamInfo) {
        try {
            return WebResponse.resSuccess("取消点赞成功",likeService.updateLike(request,ParamInfo.getEssayId()));
        } catch (Exception ex) {
            log.error("取消点赞失败",ex);
            return WebResponse.resFail("取消点赞失败",null);
        }
    }

    @ApiOperation("统计当前用户被点赞数,粉丝，关注")
    @GetMapping("getLikeCount")
    public WebResponse getLikeCount(HttpServletRequest request) {
        try {
            return WebResponse.resSuccess("统计当前用户被点赞数成功,粉丝，关注",likeService.getLikeCount(request));
        } catch (Exception ex) {
            log.error("统计当前用户点赞数失败",ex);
            return WebResponse.resFail("统计当前用户点赞数失败,粉丝，关注",null);
        }
    }

}
